﻿using System;
using System.Data;
using System.Collections.Generic;
using TCKQKL.DAL.IDAL;
using TCKQKL.Service.DataContract;
using TCKQKL.DAL.Converter;
using System.Data.OleDb;


namespace TCKQKL.DAL.Oracle
{
    public class MarketSummary
    {
        private OleDbConnection _internalConnection;
        private OleDbTransaction _internalADOTransaction = null;

        public void BeginADOTransaction()
        {
            if (_internalConnection.State != System.Data.ConnectionState.Open)
                _internalConnection.Open();
            _internalADOTransaction = _internalConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
        }
        public void RollBackTransaction()
        {
            _internalADOTransaction.Rollback();
            _internalADOTransaction = null;
        }
        public void CommitADOTransaction()
        {
            _internalADOTransaction.Commit();
            _internalADOTransaction = null;
        }
        public void Open(string connString)
        {
            if (_internalConnection == null)
                _internalConnection = new OleDbConnection(connString);
            if (_internalConnection.State != ConnectionState.Open)
                _internalConnection.Open();
        }
        public void Close()
        {
            if (_internalConnection != null && _internalConnection.State != System.Data.ConnectionState.Closed)
                _internalConnection.Close();
        }
        public MarketSummaryDataModel getMarketSummary()
        {
            return null;
        }
        public StocksDataModel getQuote(string symbol)
        {
            return null;
        }

        //SQL strings
        private const string GET_TRADING_DATE = "SELECT * FROM IRS_CALENDAR_VIEW WHERE ROWNUM=1";
        private const string GET_QUOTE = "";

        //parameters
        public DateTime getTradingDate()
        {
            try
            {
                OleDbDataReader rdr = OleDbHelper.ExecuteReaderNoParm(_internalConnection, _internalADOTransaction, CommandType.Text, GET_TRADING_DATE);
                if (rdr.HasRows)
                {
                    rdr.Read();
                    return Convert.ToDateTime(rdr["TRADING_DATE"]);
                }
                else
                    return DateTime.Today;
            }
            catch
            {
                throw;
            }
        }
    }
}
